package cn.cvs.servlet;

import cn.cvs.pojo.Rent;
import cn.cvs.servive.RentServive;
import com.sun.xml.internal.bind.v2.model.core.ID;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet("/AddServive")
public class AddServive extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();

        Rent rent = new Rent();
        RentServive servive = new RentServive();

        String userName = request.getParameter("userName");
        String carNum = request.getParameter("carNum");
        String maturityDale = request.getParameter("maturityDale");

        rent.setUserName(userName);
        rent.setCarNum(carNum);
        rent.setMaturityDale(maturityDale);
        rent.setStatus(0);


        int count = servive.addRent(rent);
        if (count>0){
            out.print("<script>alert('添加成功');location.href='ListServlet'</script>");
        }else {
            out.print("<script>alert('添加失败');location.href='list.jsp'</script>");
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
